<template>
	<view>
		<HeaderBar title="订单核销" :opacity="opacity" color="#fff" />
		<view class="bg"></view>
		<u-gap :height="34"></u-gap>
		<view class="content">
			<view class="content-title">扫码核销</view>
			<view class="content-subTitle">出示二维码给体检机构</view>
		</view>
		<view class="qrCode">
			<image :src="ossUrl + url" mode="" class="qrCode-img"></image>
			<view class="qrCode-title">您可以出示此二维码给体检中心
				以此核销订单</view>
			<view class="qrCode-btn" @click="save">保存二维码</view>
		</view>
	</view>
</template>

<script>
	import HeaderBar from "@/components/header/header.vue"
	export default {
		components: {
			HeaderBar
		},
		data() {
			return {
				opacity: 0,
				url: ''
			};
		},
		onLoad() {
			this.url = uni.getStorageSync('qrcode')
		},
		methods: {
			save() {
				uni.downloadFile({
					url: this.ossUrl + this.url, // 这里填写网络图片的地址
					success: res => {
						if (res.statusCode === 200) {
							// 图片下载成功，接下来可以保存到相册
							this.saveToPhotosAlbum(res.tempFilePath);
						} else {
							uni.showToast({
								title: '图片下载失败',
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: function(err) {
						uni.showToast({
							title: '下载图片时出错',
							content: JSON.stringify(err),
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			saveToPhotosAlbum(tempFilePath) {
				uni.saveImageToPhotosAlbum({
					filePath: tempFilePath,
					success: function(res) {
						uni.showToast({
							title: '图片保存成功',
							icon: 'none',
							duration: 2000
						});
					},
					fail: function(err) {
						uni.showToast({
							title: '保存图片到相册失败',
							content: JSON.stringify(err),
							icon: 'none',
							duration: 2000
						});
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.bg {
		width: 100%;
		height: 300rpx;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -1;
		background: #0065FF;

	}

	.qrCode {
		width: 100vw;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		padding: 100rpx 0;

		.qrCode-img {
			width: 400rpx;
			height: 400rpx;
			margin-bottom: 90rpx;
		}

		.qrCode-title {
			color: #000000;
			text-align: center;
			font-family: "PingFang SC";
			font-size: 28rpx;
			font-style: normal;
			font-weight: 500;
			margin-bottom: 116rpx;
		}

		.qrCode-btn {
			width: 364rpx;
			height: 90rpx;
			flex-shrink: 0;
			fill: #0065FF;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #0065FF;
			font-family: "PingFang SC";
			font-size: 36rpx;
			font-style: normal;
			font-weight: 500;
			background: #E6F0FF;
			border-radius: 46rpx;
		}
	}

	.content {
		width: 100%;
		position: relative;
		background: white;
		box-sizing: border-box;
		padding: 0 40rpx;
		margin-bottom: 58rpx;

		.content-title {
			color: #112950;
			font-family: "PingFang SC";
			font-size: 48rpx;
			font-style: normal;
			font-weight: 400;
			margin-bottom: 4rpx;
		}

		.content-subTitle {
			color: #b2bac6;
			font-family: "PingFang SC";
			font-size: 30rpx;
			font-style: normal;
			font-weight: 400;
		}
	}

	.content::before {
		content: "";
		width: 100%;
		height: 45rpx;
		background: white;
		border-top-right-radius: 50rpx;
		position: absolute;
		top: -42rpx;
		left: 0;
	}
</style>